package conan.Test;

import conan.DomainLayer.Kunde;


import conan.dataSource.UnitOfWork;

import java.sql.Connection;

public class TestKundeDb
{
    private UnitOfWork work;

    public TestKundeDb()
    {
        work = new UnitOfWork();
        //testGet();
        createNewKunde();
        System.out.println(work.toString());
        try
        {
            work.commit();
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }


    }

    public static void main(String[] args)
    {
        new TestKundeDb();
    }

    public void testGet()
    {
        System.out.println("testGet");
        /*
        DB db = new DB();
        Connection conn = db.getConnection();
        KundeMapper mapper = new KundeMapper();
        Kunde kunde = mapper.getKunde(2, conn);
        System.out.println(kunde);
        */

        Kunde kunde = work.getKunde(2);
        System.out.println(kunde);

    }

    public Kunde createNewKunde()
    {
        Kunde currentKunde;
        //== start new Business transaction     
        int newKundeNo = work.getNextKundeNo(); // DB-generated unique ID
        if (newKundeNo != 0)
        {
            currentKunde = new Kunde(newKundeNo, "FCK");
            work.registerNewKunde(currentKunde);
        }
        else
        {
            currentKunde = null;
        }
        return currentKunde;
    }
}
